package org.lds.message.center.admin.business.template.controller;

import com.unisound.tracelog.client.annotation.TraceLog;
import lombok.extern.slf4j.Slf4j;
import org.lds.message.center.admin.business.template.model.request.*;
import org.lds.message.center.admin.business.template.model.response.*;
import org.lds.message.center.admin.business.template.service.TemplateBaseService;
import org.lds.message.center.common.model.ResultDTO;
import org.lds.message.center.common.model.db.OrderBy;
import org.lds.message.center.common.model.db.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2024-12-22
 */
@Slf4j
@RestController
@RequestMapping("/api/common/template")
public class TemplateBaseController {

    @Autowired
    private TemplateBaseService templateBaseService;

    /**
     * 创建
     */
    @TraceLog("创建模板")
    @PostMapping("/create")
    public ResultDTO<TemplateBaseResponse> createTemplate(@RequestBody @Validated TemplateBaseCreateRequest request) {
        return templateBaseService.createTemplate(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<TemplateBaseBatchCreateResponse> batchCreateTemplate(@RequestBody @Validated TemplateBaseBatchCreateRequest request) {
        return templateBaseService.batchCreateTemplate(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<TemplateBaseDeleteResponse> deleteTemplate(@RequestBody TemplateBaseDeleteRequest request) {
        return templateBaseService.deleteTemplate(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<TemplateBaseBatchDeleteResponse> batchDeleteTemplate(@RequestBody @Validated TemplateBaseBatchDeleteRequest request) {
        return templateBaseService.batchDeleteTemplate(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<TemplateBaseResponse> updateTemplate(@RequestBody @Validated TemplateBaseUpdateRequest request) {
        return templateBaseService.updateTemplate(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<TemplateBaseBatchUpdateResponse> batchUpdateTemplate(@RequestBody @Validated TemplateBaseBatchUpdateRequest request) {
        return templateBaseService.batchUpdateTemplate(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<TemplateBaseListResponse> listTemplate(@RequestBody TemplateBaseListRequest request) {
        return templateBaseService.listTemplate(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<TemplateBaseListResponse> listAllTemplate(@RequestBody OrderBy orderBy) {
        return templateBaseService.listAllTemplate(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<TemplateBaseResponse> getTemplateById(@RequestBody @Validated TemplateBaseGetByIdRequest request) {
        return templateBaseService.getTemplateById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<TemplateBaseListResponse> getTemplateByIds(@RequestBody @Validated TemplateBaseGetByIdsRequest request) {
        return templateBaseService.getTemplateByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<TemplateBaseResponse>> listTemplatePage(@RequestBody TemplateBaseListPageRequest request) {
        return templateBaseService.listTemplatePage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated TemplateBaseGetByKeyRequest request) {
        return ResultDTO.success(templateBaseService.getTemplateByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<TemplateBaseBatchCreateResponse> batchCreateTemplateAsync(@RequestBody @Validated TemplateBaseBatchCreateRequest request) {
        return templateBaseService.batchCreateTemplateAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<TemplateBaseBatchDeleteResponse> batchDeleteTemplateAsync(@RequestBody @Validated TemplateBaseBatchDeleteRequest request) {
        return templateBaseService.batchDeleteTemplateAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<TemplateBaseBatchUpdateResponse> batchUpdateTemplateAsync(@RequestBody @Validated TemplateBaseBatchUpdateRequest request) {
        return templateBaseService.batchUpdateTemplateAsync(request);
    }

}